
_realname=libbacktrace
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
_commit='1db85642e3fca189cf4e076f840a45d6934b2456'
pkgver=r115.1db8564
pkgrel=1
pkgdesc="Library to produce symbolic backtraces (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/ianlancetaylor/libbacktrace"
msys2_repository_url=${url}
msys2_references=(
  'purl: pkg:github/ianlancetaylor/libbacktrace'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             'git')
source=("git+${msys2_repository_url}.git#commit=${_commit}"
        "0001-libbacktrace-no-undefined.patch"
        "libbacktrace.pc")
sha256sums=('3c5ebe9ae7a92e2f2e451211ee0c544ac9f035aa28c7195fe36fd9911088abcb'
            'cd4b22ecf0c775407919144a3adcb1a2069829432d65b6e019bfbcc5f3cef91e'
            '4f17323b633a0d0a80dc1ff29855c0caa7946562aa3a22d2fae4e426122d16ca')

pkgver() {
  cd "${_realname}"
  printf "r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

prepare () {
  cd "${_realname}"

  # dont allow undefined symbols to build the dll
  git apply "${srcdir}/0001-libbacktrace-no-undefined.patch"

  autoreconf -vfi
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd build-${MSYSTEM}

  make install DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}"/${_realname}/LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE

  # pkg-config
  install -Dm644 "${srcdir}/${_realname}.pc" "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/${_realname}.pc"
  sed -i "s|@MINGW_PREFIX@|${MINGW_PREFIX}|g" "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/${_realname}.pc"
}
